﻿Imports System.Linq

Public Class GroupWrapper
#Region "Properties"

    Public _description As String
    Public Property Description As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property

    Public _site As String
    Public Property Site As String
        Get
            Return _site
        End Get
        Set(ByVal value As String)
            _site = value
        End Set
    End Property

    Public _department As String
    Public Property Department As String
        Get
            Return _department
        End Get
        Set(ByVal value As String)
            _department = value
        End Set
    End Property

    Public _numberOfUsers As Integer
    Public Property NumberOfUsers As Integer
        Get
            Return _numberOfUsers
        End Get
        Set(ByVal value As Integer)
            _numberOfUsers = value
        End Set
    End Property

#End Region

    Public Shared Function ConvertToWrapperList(ByVal source As IEnumerable(Of Equipment.DataAccess.Group)) As List(Of GroupWrapper)
        Dim wrapperList As New List(Of GroupWrapper)

        For Each g In source
            Dim w As New GroupWrapper
            w.Description = g.Description
            w.Department = g.SiteDepartment.Description
            If g.SiteDepartment.Parent IsNot Nothing Then
                w.Site = g.SiteDepartment.Parent.Description
            Else
                w.Site = String.Empty
            End If
            w.NumberOfUsers = g.UserGroups.Count()

            wrapperList.Add(w)
        Next

        Return wrapperList
    End Function
End Class
